#!/usr/bin/python
#Copyright (c) 2007-2008 Travis Fickett (tfickett at ufl dot edu)
#
#Permission is hereby granted, free of charge, to any person
#obtaining a copy of this software and associated documentation
#files (the "Software"), to deal in the Software without
#restriction, including without limitation the rights to use,
#copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the
#Software is furnished to do so, subject to the following
#conditions:
#
#The above copyright notice and this permission notice shall be
#included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
#EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
#OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
#NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
#HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
#WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
#FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
#OTHER DEALINGS IN THE SOFTWARE.

#pygtk viewer for pynmea
#work in progress, not working yet but added to source control
#import sys
from pyNMEA import pyNMEAparser
import pygtk
import gtk
import gtk.glade
import gobject
import serial

class pyNav:
    nmeap = pyNMEAparser()
    serialfd = serial.Serial()
    serialfd.baudrate = 4800
    serialfd.port = 0
    
    def cbGrabSerial(self, src, condi):
    	pass
    	#print "condi"+str(condi)
    	return True
    def cbToggleSerial(self, src):
    	if (src.active == True):
    		self.serialfd.open()
    		assert self.serialfd.isOpen() == True
    		return True
    	else:
    		if (self.serialfd.isOpen()==True):
    			self.serialfd.close()
    		return True
    def __init__(self):	
		#Set the Glade file
		self.gladefile = "pynav2.glade"  
		self.wTree = gtk.glade.XML(self.gladefile) 
		#self.serialfd = open("/dev/urandom")
		#Get the Main Window, and connect the "destroy" event
		self.window = self.wTree.get_widget("window1")
		if (self.window):
		    self.window.connect("destroy", gtk.main_quit)
		self.quitbttn = self.wTree.get_widget("quitmenuitem")
		if (self.quitbttn):
			self.quitbttn.connect("activate", gtk.main_quit)
		self.soglab = self.wTree.get_widget("soglabel")
		self.soglab.set_text("supworld")
		self.serialtog = self.wTree.get_widget("enableserial")
		self.serialtog.connect("toggled", self.cbToggleSerial)
		print self.serialfd.portstr
		#self.iowatch = gobject.io_add_watch(self.serialfd,  gobject.IO_IN, self.cbGrabSerial)

if __name__ == "__main__":
    print "Starting under name: ",__name__
    hwg = pyNav()
    gtk.main()
    hwg.serialfd.close()
